import { Image } from "leafer-ui";
import { MoveDirectionBlack } from "./moveDirectionBlack";
import { DirectionType } from ".";
import { Wall } from "./wall";
import { Tank } from "./tank";

export class Bullet extends MoveDirectionBlack {
  static width = 10;
  static height = 20;
  ascriptionTankId: string;
  constructor({
    x,
    y,
    direction,
    ascriptionTankId,
  }: {
    x: number;
    y: number;
    direction: DirectionType;
    ascriptionTankId: string;
  }) {
    const bullet = new Image({
      url: "/zidan.png",
      draggable: false,
      width: 10,
      height: 20,
      x,
      y,
    });
    super({
      x,
      y,
      speed: 8,
      width: Bullet.width,
      height: Bullet.height,
      targter: bullet,
      direction,
      isRadiusPoint: true,
    });
    this.ascriptionTankId = ascriptionTankId;
  }
  move(code: DirectionType): void {
    const item = this.isCollide(code);
    if (item instanceof Wall) {
      this.remove();
      return item.destroy({ mode: this.actionDirection, value: 1 });
    } else if (item instanceof Tank && item.id !== this.ascriptionTankId) {
      this.remove();
      return item.bloodVolume();
    }
    super.move(code);
  }
}
